package servlet;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/a")
public class AServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// 得到参数
		String name = req.getParameter("name");
		System.out.println("name=" + name);
		
		req.setAttribute("age", 10);  // 属性被添加add
		req.setAttribute("age", 20);  // 属性被替换replace
		//req.removeAttribute("age");   // 属性被移除remove
		
		HttpSession session = req.getSession();
		session.setAttribute("sex", "男");
		
		ServletContext app = this.getServletContext();
		app.setAttribute("title", "三个作用域");
		// 转发
		req.getRequestDispatcher("/b").forward(req, resp);
	}
	
}
